package com.smartcruise.util.network.customerObserver;

import com.smartcruise.util.network.callBack.BaseCallBack;
import com.smartcruise.util.network.netUtils.NetContract;
import com.smartcruise.util.network.netUtils.Result;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by FengChaoQun
 * on 2018/2/6 0006
 * 不显示加载框的Observer
 * 接受{@link Result}作为网络请求结果
 * 对返回的结果进行分类 然后交给{@link BaseCallBack}处理
 */

public class SimpleBackObserver implements Observer<Result> {

    private BaseCallBack callBack;

    public SimpleBackObserver(BaseCallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    public void onSubscribe(Disposable disposable) {

    }

    @Override
    public void onNext(Result result) {
        if (NetContract.isSuccess(result)) {
            callBack.onSuccess(result);
        } else {
            callBack.onFail(result);
        }
    }

    @Override
    public void onError(Throwable throwable) {
        callBack.onError(throwable);
    }

    @Override
    public void onComplete() {

    }
}
